<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/11/22
  Time: 9:26
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <c:set var="root" value="${pageContext.request.contextPath}"/>
    <meta http-equiv="Content-Language" content="zh-cn">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script src="${root}/bootstrap/js/jquery-2.1.0.js"></script>
    <link href="${root}/bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />
    <script src="${root}/bootstrap/js/bootstrap.js"></script>

    <style type="text/css">
        #biaoti{
            height: 24px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
    </style>
    <title>产品列表</title>
</head>
<body>
  <div style="background-color: #f5fafe;width: 100%;height: 100%" class="container-fluid">
      <div class="row">
          <c:forEach var="c" items="${page.pageList}" varStatus="status">
              <div class="col-xs-2">
                  <div class="thumbnail">
                      <img src="${root}/${c.image}" alt="" style="height: 20%">
                      <div class="caption">
                          <h5 id="biaoti">${c.pname}</h5>
                          <p>市场价：${c["market_price"]}</p>

                          <p>是否热销：
                              <c:if test="${c[\"is_hot\"] eq 1}">是</c:if>
                              <c:if test="${c[\"is_hot\"] ne 1}">否</c:if>
                          </p>
                          <p><a href="#" class="btn btn-primary btn-sm" role="button">修改</a> <a href="#" class="btn btn-default btn-sm" role="button">删除</a></p>
                      </div>
                  </div>
              </div>
          </c:forEach>

      </div>

      <%--
        规则是：前5 后四   10
        当前页：page
        开始：begin;
        结束：end
        if(总页数 《=10)｛
            begin = 1;
            end = 总页数;
        ｝else{  //页数超过10页    当前选择了第四页       共20页
            begin = page-5;   4-5 =-1 //
            end = page +4;
            if(begin <1){
                begin = 1;
                end = 10;
            }
            if(end > 总页数){
                end = 总页数;
                begin = 总页数 - 9;
            }
        }
      --%>

     <c:choose>
         <c:when test="${page.pageCount <=10}">
             <c:set var="begin" value="1"/>
             <c:set var="end" value="${page.pageCount}"/>
         </c:when>
         <c:otherwise>
             <c:set var="begin" value="${page.page -5}"/>
             <c:set var="end" value="${page.page +4}"/>
             <c:if test="${begin<1}">
                 <c:set var="begin" value="1"/>
                 <c:set var="end" value="10"/>
             </c:if>
             <c:if test="${end > page.pageCount}">
                 <c:set var="begin" value="${page.pageCount-9}"/>
                 <c:set var="end" value="${page.pageCount}"/>
             </c:if>
         </c:otherwise>
     </c:choose>

      <nav aria-label="...">
          <ul class="pagination">
              <c:if test="${page.page ne 1}">
                  <li ><a href="${root}/AdminProductFindALL?page=${page.page-1}" aria-label="Previous"><span aria-hidden="true">&laquo;</span></a></li>
              </c:if>

              <c:forEach var="num" begin="${begin}" end="${end}">
                  <c:choose>
                      <c:when test="${page.page eq num}">
                          <li class="active"><span>${num} <span class="sr-only">(current)</span></span></li>
                      </c:when>
                      <c:otherwise>
                          <li><a href="${root}/AdminProductFindALL?page=${num}">${num}<span class="sr-only">(current)</span></a></li>
                      </c:otherwise>
                  </c:choose>

              </c:forEach>

              <c:if test="${page.page ne page.pageCount}">
                  <li ><a href="${root}/AdminProductFindALL?page=${page.page+1}" aria-label="Previous"><span aria-hidden="true">&raquo;</span></a></li>
              </c:if>

          </ul>
      </nav>

  </div>
</body>
</html>
